import 'package:dio/dio.dart';

class NetResult<T> {
  int code;
  String msg;
  T data;
  NetResult({required this.code, required this.msg, required this.data});
}

class NetRequest<T> {
  int code = 0;
  String msg = '';
  // T data = null as T;

  static Dio dio = new Dio();
  request({
    required String url,
    String method = 'get',
    Map<String, dynamic>? queryParams,
    Map<String, dynamic>? data}) async {
    try {
      Response response = await dio.request(
        url,
        queryParameters: queryParams,
        data: data,
        options: Options(method: method),
      );
      // print(response);
      return NetResult<T>(code: response.data['code'], msg: response.data['msg'], data: response.data['data']);
    } catch (e) {
      print("dio catch e => " + e.toString());
      throw e;
    }
  }
}